//
//  SendSuggestViewController.m
//  Lucky28
//
//  Created by zr on 2018/8/2.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "SendSuggestViewController.h"

@interface SendSuggestViewController () <UITextViewDelegate>

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UITextView * textView;
@property (nonatomic, weak)UIButton * finishButton;

@end

@implementation SendSuggestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    self.view.backgroundColor = ColorWithRGB(0xE8E8E8);
    self.title = @"Feedback";
    self.view.backgroundColor = ZRWhiteColor;
    
    [self setupUI];
}


- (void)setupUI{

    // 创建textView
    UITextView *textView =[[UITextView alloc]initWithFrame:CGRectMake(15,20 + kNavHeight,kScreenW - 30,300)];
    textView.backgroundColor= ZRWhiteColor;
    textView.text = @"say something...";
    textView.font = [UIFont systemFontOfSize:15];
    textView.textColor = ColorWithRGB(0xbebebe);
    textView.delegate = self;
    textView.layer.cornerRadius = 5;
    textView.layer.borderColor = [[UIColor grayColor] CGColor];
    textView.layer.borderWidth = 1;
    textView.layer.masksToBounds = YES;
    
    self.textView = textView;
    [self.view addSubview:self.textView];
    
    
    UIButton * finishButton = [UIButton new];
    
    [finishButton setTitle:@"submit" forState:UIControlStateNormal];
    [finishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [finishButton setBackgroundColor:[UIColor colorWithHexString:@"32AEFF"]];
    [finishButton addTarget:self action:@selector(clickFinishButton) forControlEvents:UIControlEventTouchUpInside];
    finishButton.titleLabel.font = [UIFont systemFontOfSize:17];
    
    self.finishButton = finishButton;
    
    [self.view addSubview:self.finishButton];
}


- (void)viewDidLayoutSubviews{
    
    [self.finishButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(40);
        make.trailing.mas_equalTo(self.view).offset(-40);
        make.bottom.mas_equalTo(self.textView.mas_bottom).offset(100);
        make.height.mas_equalTo(40);
    }];
}


- (void)clickFinishButton{
    
    if ([self.textView.text isEqualToString:@"say something..."] || self.textView.text.length == 0) {
        
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                  message:@"Please, say something!"
                                                                           preferredStyle:UIAlertControllerStyleAlert];
                   
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                         handler:^(UIAlertAction * action) {
                                                                             
                                                                             
                                                                         }];
                   
        [alert addAction:defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
    }else{
        
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                  message:@"We will deal with it as soon as possible！"
                                                                           preferredStyle:UIAlertControllerStyleAlert];
                   
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                         handler:^(UIAlertAction * action) {
                                                                             
                                                                             [self.navigationController popViewControllerAnimated:YES];
                                                                         }];
                   
        [alert addAction:defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
}


#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    
    if(textView.text.length < 1){
        textView.text = @"say something...";
        textView.textColor = ColorWithRGB(0xbebebe);
    }else{
        
        [textView resignFirstResponder];
    }
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"say something..."]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.textView resignFirstResponder];
//    [self.textView endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
